/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package com.xy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xy.dto.PositionGroupViewerTypeDTO;
import com.xy.entity.PositionGroupViewerTypeEntity;
import com.xy.entity.ViewerEntity;
import com.xy.entity.ViewerSortEntity;
import com.xy.service.IExhibitionService;
import com.xy.service.IViewerService;
import com.xy.service.IViewerSortService;
import com.xy.vo.PositionGroupViewerTypeVO;
import com.xy.excel.PositionGroupViewerTypeExcel;
import com.xy.mapper.PositionGroupViewerTypeMapper;
import com.xy.service.IPositionGroupViewerTypeService;
import com.xy.wrapper.PositionGroupViewerTypeWrapper;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import java.util.List;

/**
 * 门禁组与票证类型关系表 服务实现类
 *
 * @author BladeX
 * @since 2023-07-18
 */
@Service
@AllArgsConstructor
public class PositionGroupViewerTypeServiceImpl extends BaseServiceImpl<PositionGroupViewerTypeMapper, PositionGroupViewerTypeEntity> implements IPositionGroupViewerTypeService {

	private final IViewerSortService viewerSortService;

	@Override
	public IPage<PositionGroupViewerTypeVO> selectPositionGroupViewerTypePage(IPage<PositionGroupViewerTypeVO> page, PositionGroupViewerTypeVO positionGroupViewerType) {
		return page.setRecords(baseMapper.selectPositionGroupViewerTypePage(page, positionGroupViewerType));
	}

	@Override
	public IPage<PositionGroupViewerTypeVO> listPage(PositionGroupViewerTypeDTO positionGroupViewerType, Query query) {
		IPage<PositionGroupViewerTypeEntity> pages = this.page(Condition.getPage(query), Condition.getQueryWrapper(positionGroupViewerType));
		IPage<PositionGroupViewerTypeVO> page = PositionGroupViewerTypeWrapper.build().pageVO(pages);
		List<PositionGroupViewerTypeVO> typeVOList = page.getRecords();
		typeVOList.stream().forEach(o->{
			ViewerSortEntity viewerSort = viewerSortService.getById(o.getViewerTypeId());
			BeanUtils.copyProperties(viewerSort,o,"id");
		});
		return page.setRecords(typeVOList);
	}

	@Override
	public Boolean updatePositionGroupViewerType(PositionGroupViewerTypeDTO positionGroupViewerType) {
		LambdaQueryWrapper<PositionGroupViewerTypeEntity> wrapper = Wrappers.lambdaQuery();
		wrapper.eq(PositionGroupViewerTypeEntity::getPositionGroupId,positionGroupViewerType.getPositionGroupId());
		List<PositionGroupViewerTypeEntity> typeEntityList = this.list(wrapper);
		typeEntityList.forEach(o->{
			o.setFrontBack(positionGroupViewerType.getFrontBack());
		});
		return this.updateBatchById(typeEntityList);
	}


	@Override
	public List<PositionGroupViewerTypeExcel> exportPositionGroupViewerType(Wrapper<PositionGroupViewerTypeEntity> queryWrapper) {
		List<PositionGroupViewerTypeExcel> positionGroupViewerTypeList = baseMapper.exportPositionGroupViewerType(queryWrapper);
		//positionGroupViewerTypeList.forEach(positionGroupViewerType -> {
		//	positionGroupViewerType.setTypeName(DictCache.getValue(DictEnum.YES_NO, PositionGroupViewerType.getType()));
		//});
		return positionGroupViewerTypeList;
	}

}
